﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DLULearningNetworkModel
{
    public partial class IDNumber
    {
        public static IDNumber SelectByCode(string code)
        {
            try
            {
                using (DLULNEntities db = new DLULNEntities())
                {
                    return db.IDNumbers.SingleOrDefault(c => c.Code_s == code);
                }
            }
            catch 
            {
                return null;   
            }
        }

        public static int UpdateIsUseField(int idNumberID)
        {
            try
            {
                using (DLULNEntities db = new DLULNEntities())
                {
                    IDNumber idNumber = db.IDNumbers.SingleOrDefault(c => c.IDNumberID_i == idNumberID);
                    if (idNumberID != null)
                    {
                        idNumber.IsUse_b = true;
                        if (db.SaveChanges() > 0)
                        {
                            return 1;
                        }
                    }
                    return 0;
                }
            }
            catch 
            {
                return 101;   
            }
        }
    }
}
